package com.muye.dianli.fragment;

import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.muye.constant.C;
import com.muye.dianli.R;
import com.muye.dianli.activity.FollowDetailActivity;
import com.muye.dianli.activity.LinkageCommidityListActivity;
import com.muye.field.HomePageListData;
import com.zvezda.android.utils.BaseUtils;
import com.zvezda.disply.utils.DisplayConfig;
import com.zvezda.disply.utils.DisplayManager;

/**
 * 主页产品碎片
 * 
 * @author TangChao
 *
 */
public class MainFragment3 extends Fragment implements OnClickListener
{
	private List<HomePageListData> arrayList;
	
	public List<HomePageListData> getArrayList()
	{
		return arrayList;
	}
	
	public void setArrayList(List<HomePageListData> arrayList)
	{
		this.arrayList = arrayList;
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
	{
		View view = inflater.inflate(R.layout.main_fragment3_layout, null);
		ImageView imageView0 = (ImageView) view.findViewById(R.id.fragment3_image_view0);
		imageView0.setOnClickListener(this);
		ImageView imageView1 = (ImageView) view.findViewById(R.id.fragment3_image_view1);
		imageView1.setOnClickListener(this);
		ImageView imageView2 = (ImageView) view.findViewById(R.id.fragment3_image_view2);
		imageView2.setOnClickListener(this);
		ImageView imageView3 = (ImageView) view.findViewById(R.id.fragment3_image_view3);
		imageView3.setOnClickListener(this);
		ImageView imageView4 = (ImageView) view.findViewById(R.id.fragment3_image_view4);
		imageView4.setOnClickListener(this);
		ImageView imageView5 = (ImageView) view.findViewById(R.id.fragment3_image_view5);
		imageView5.setOnClickListener(this);
		ImageView imageView6 = (ImageView) view.findViewById(R.id.fragment3_image_view6);
		imageView6.setOnClickListener(this);
		TextView imageView7 = (TextView) view.findViewById(R.id.fragment3_image_view7);
		imageView7.setText("产品");
		imageView7.setOnClickListener(this);
		/* ===================== */
		DisplayManager.getInstance().open(getActivity());
		showPicure(0, 120, 120, imageView0);
		showPicure(1, 120, 120, imageView1);
		showPicure(2, 120, 120, imageView2);
		showPicure(3, 120, 120, imageView3);
		showPicure(4, 240, 240, imageView4);
		showPicure(5, 120, 120, imageView5);
		showPicure(6, 120, 120, imageView6);
		// showPicure(7, 240, 240, imageView7);
		return view;
	}
	
	/**
	 * 显示图片
	 */
	private void showPicure(int position, int w, int h, ImageView imageView)
	{
		String picUrl;
		try
		{
			picUrl = arrayList.get(position).logoUrl;
		}
		catch (Exception e)
		{
			e.printStackTrace();
			picUrl = "http://115.28.138.45/uploads/201402/530f3eb8a264d.jpg";
		}
		DisplayConfig displayConfig = new DisplayConfig();
		displayConfig.path = BaseUtils.getFilePath(C.FILE_PATH, picUrl);
		displayConfig.url = picUrl;
		displayConfig.w = w;
		displayConfig.h = h;
		displayConfig.defaultRes = R.drawable.ic_launcher;
		displayConfig.imageView = imageView;
		DisplayManager.getInstance().display(displayConfig);
	}
	
	@Override
	public void onClick(View v)
	{
		switch (v.getId())
		{
			case R.id.fragment3_image_view0:
				Intent intent0 = new Intent(getActivity(), FollowDetailActivity.class);
				startActivity(intent0);
				break;
			case R.id.fragment3_image_view1:
				Intent intent1 = new Intent(getActivity(), FollowDetailActivity.class);
				startActivity(intent1);
				break;
			case R.id.fragment3_image_view2:
				Intent intent2 = new Intent(getActivity(), FollowDetailActivity.class);
				startActivity(intent2);
				break;
			case R.id.fragment3_image_view3:
				Intent intent3 = new Intent(getActivity(), FollowDetailActivity.class);
				startActivity(intent3);
				break;
			case R.id.fragment3_image_view4:
				Intent intent4 = new Intent(getActivity(), FollowDetailActivity.class);
				startActivity(intent4);
				break;
			case R.id.fragment3_image_view5:
				Intent intent5 = new Intent(getActivity(), FollowDetailActivity.class);
				startActivity(intent5);
				break;
			case R.id.fragment3_image_view6:
				Intent intent6 = new Intent(getActivity(), FollowDetailActivity.class);
				startActivity(intent6);
				break;
			case R.id.fragment3_image_view7:
				Intent intent7 = new Intent(getActivity(), LinkageCommidityListActivity.class);
				intent7.putExtra("TITLE_NAME", "产品");
				startActivity(intent7);
				break;
			
			default:
				break;
		}
	}
}
